package com.sd.view;

import java.util.Vector;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sd.activity.r.R;
import com.sd.reader.ReadAttribute;
import com.sd.reader.ReaderSet;

public class BgAdapter extends BaseAdapter {

	private Vector<ReadAttribute> mBgs;
	private LayoutInflater mLayoutInflater;
	private Context mContext;
	private int readbg0;
	public BgAdapter(Context context,Vector<ReadAttribute> bgs){
		mContext = context;
		mBgs = bgs;
		mLayoutInflater = LayoutInflater.from(context);
		readbg0 = ReaderSet.getInstance().getReadBg();
	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mBgs.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mBgs.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if(convertView==null){
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.bgview, null);
			holder.bookName = (ImageView)convertView.findViewById(R.id.bg);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		ReadAttribute attribute = (ReadAttribute)mBgs.get(position);
		holder.bookName.setImageResource((Integer)attribute.mKey);
		if(readbg0 == (Integer)attribute.mValue){
			holder.bookName.setSelected(true);
		}else{
			holder.bookName.setSelected(false);
		}
		return convertView;
	}
	
	class ViewHolder {
		/**
		 * 做法名字
		 */
		ImageView book1;
		/**
		 * 做法介绍
		 */
		ImageView bookName;
		/**
		 * 做法加价
		 */
		TextView bookreadInfo;
	}
	
	
}
